/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mvc.example.persistence.dao;

import java.util.HashMap;
import java.util.Map;
import mvc.example.persistence.dao.exception.DAOException;
import mvc.example.persistence.dao.impl.StudentDAOImplJDBC;

/**
 *
 * @author zeta
 */
public class DAOFactory {
        
    private static final Map<Class<? extends DAO>, Class<?>> map;
    
    static  {
        map =  new HashMap<Class<? extends DAO>, Class<?>>();
        map.put(StudentDAO.class, StudentDAOImplJDBC.class);
    }
    
    private DAOFactory() {
    }
    
    public static <T extends DAO> T getDAO(Class<T> clazz) throws DAOException{
        try {
            //crea una nueva instancia de la implementacion de la clase de interfaz que recibe como parametro
            return (T) map.get(clazz).newInstance();
        } catch (InstantiationException ex) {
            throw new DAOException(ex.getMessage());
        } catch (IllegalAccessException ex) {
            throw new DAOException(ex.getMessage());
        }
    }
}
